<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class UserRegList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "003申请列表ok";
    public $group = '租房';
    public $desc = "";

    public $input = [
    ];

    public $output = [
        'list' => [
            [
                'id' => 'label=id;',
                'uid' => 'label=申请人uid;',
                'reg_real_name' => 'label=申请人真实姓名;',
                'reg_sex' => 'label=性别： 0女 1男 2未知;',
                'reg_idcard' => 'label=申请人身份证号码;',
                'reg_mobile' => 'label=申请人联系电话;',
                'reg_age' => 'label=申请人年龄;',
                'home_num' => 'label=家庭人口数;',
                'company' => 'label=工作单位;',
                'company_contact' => 'label=公司经办人姓名;',

                'company_mobile' => 'label=公司经办人联系电话;',
                'contact_real_name' => 'label=通讯联系人姓名;',
                'contact_idcard' => 'label=通讯人身份证;',
                'contact_address' => 'label=通讯人地址;',
                'state' => 'label=状态: 1提交申请 2内部审批 3审批成功 4审批失败 5取消审批;',
                'create_time' => 'label=申请时间;',
                'type' => 'label=类型;comment=1个人 2单位',
            ]
        ]
    ];

    public function run($param, $uid)
    {
        $page_num = $param['page_num'] ?: 1;
        $page_size = $param['page_size'] ?: 10;

        $list = M('user_reg')
            ->where([
                'uid' => $uid,
            ])
            ->order('id desc')->page($page_num, $page_size)
            ->select();
        foreach ($list as &$item) {
            $item['type'] = 1;
        }
        $list_c = M('company_reg')
            ->where([
                'uid' => $uid,
            ])
            ->order('id desc')->page($page_num, $page_size)
            ->select();
        foreach ($list_c as &$item) {
            $item['type'] = 2;
            $list[] = $item;
        }
       asort($list, 'create_time');
        return [
            'list'=> $list,
        ];
    }
}
